package zuoye4;

import java.util.ArrayList;

public class zuoye4 {
	public static void main(String[] args) {
		ArrayList<Integer> list=new ArrayList<Integer>();
		
		suShu(list);
		huiWen(list);
	}

	private static void huiWen(ArrayList<Integer> list) {
		int count=0;
		for(int i=0;i<list.size();i++){
			if(list.get(i)<10){
				System.out.print(list.get(i)+" ");
				count++;
			}else if(list.get(i)<100&&list.get(i)>10){
				int shi=list.get(i)/10;
				int ge = list.get(i)%10;
				if(ge==shi){
					System.out.print(list.get(i)+" ");
					count++;
				}
			}else if(list.get(i)<1000&&list.get(i)>100){
				int bai=list.get(i)/100;
				int ge = list.get(i)%10;
				if(bai==ge){
					System.out.print(list.get(i)+" ");
					count++;
				}
			}
			if(count==10){
				System.out.println();
				count=0;
			}
		}
	}

	private static void suShu(ArrayList<Integer> list) {
		int flag=1;
		for(int n=2;n<=1000;n++){
			for(int i=2;i<=Math.sqrt(n);i++){
				if(n%i==0){
					flag=0;
					break;
				}
			}
			if(flag==1){
				list.add(n);
			}else{
				flag=1;
			}
		}
	}
}
